package mk.company.fin.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
//import javax.persistence.GenerationType;
import javax.persistence.Id;
//import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Index;

import mk.company.fin.FinConstants;

@Entity
@Table(name = FinConstants.Tables.USER)
public class User extends Model {

	private static final long serialVersionUID = -2911585097017053394L;

	// persistent
	private Long id;
	private String username;
	private String password;
	private String firstName;
	private String lastName;
	private String embg;
	private String language;
	private boolean active;
	
	
	@Id
	@Column(name = "id_user")
	//@SequenceGenerator(name = "user_seq", sequenceName = "user_seq", allocationSize = 1)
	@GeneratedValue//(strategy = GenerationType.SEQUENCE, generator = "user_seq")
	public Long getId() {
		return id;
	}
	
	public void setId(Long id) {
		this.id = id;
	}
	
	@Column(unique = true, nullable = false, length = 50)
	@Index(name = FinConstants.Tables.USER + "_search")
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	@Column(nullable = false, length = 100)
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(nullable = false, length = 50)
	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	@Column(nullable = false, length = 50)
	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	@Column(nullable = true, length = 13)
	public String getEmbg() {
		return embg;
	}

	public void setEmbg(String embg) {
		this.embg = embg;
	}
	
	@Column(length = 5)
	public String getLanguage() {
		return language;
	}

	public void setLanguage(String language) {
		this.language = language;
	}

	@Column
	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

	
	/**
	 * @return first + last name
	 */
	@Transient
	public String getFullName() {
		return getFirstName() + " " + getLastName();
	}

	@Deprecated
	public void setFullName(String fullName) {
		throw new UnsupportedOperationException("The field fullName is dynamic!");
	}

}
